#include <iostream>
using namespace std;
int n,m,z;
const int N=2e5+10;
int x,y;
int fa[N];
int find(int x)
{
	if(fa[x]==x)return x;
	return fa[x]==find(x);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)fa[i]=i;
	while(m--)
	{
		cin>>z>>x>>y;
		if(z==1)
		{
			int fx=find(x);
			int fy=find(y);
			fa[fx]=fy;
		}
		else
		{
			int fx=find(x);
			int fy=find(y);
			if(fx==fy)
			cout<<"Y"<<endl;
			else
			cout<<"N"<<endl;
		}
		
	}
	return 0;
}
